package com.web.base.wechat.util;

import com.blue.jdbc.Page;
import com.web.base.wechat.message.WechatRequest;
import com.web.base.wechat.message.WechatResponse;
import com.web.base.wechat.model.Wechat;

import java.util.ArrayList;
import java.util.List;

public class WechatConvertor
{
	private WechatConvertor()
	{
	}
	
	public static Wechat toWechat(WechatRequest request)
	{
		if (request == null)
			return null;
		
		Wechat wechat = new Wechat();
		wechat.setId(request.getId());
		wechat.setCode(request.getCode());
		wechat.setOpenId(request.getOpenId());
		wechat.setName(request.getName());
		wechat.setCreateTime(request.getCreateTime());
		wechat.setState(request.getState());
		wechat.setToken(request.getToken());
		wechat.setAppId(request.getAppId());
		wechat.setAppSecret(request.getAppSecret());
		wechat.setMchId(request.getMchId());
		wechat.setMchKey(request.getMchKey());
		wechat.setType(request.getType());
		wechat.setUrl(request.getUrl());
		return wechat;
	}
	
	public static WechatResponse toResponse(Wechat wechat)
	{
		if (wechat == null)
			return null;
		
		WechatResponse response = new WechatResponse();
		response.setId(wechat.getId());
		response.setCode(wechat.getCode());
		response.setOpenId(wechat.getOpenId());
		response.setName(wechat.getName());
		response.setCreateTime(wechat.getCreateTime());
		response.setState(wechat.getState());
		response.setToken(wechat.getToken());
		response.setAppId(wechat.getAppId());
		response.setAppSecret(wechat.getAppSecret());
		response.setMchId(wechat.getMchId());
		response.setMchKey(wechat.getMchKey());
		response.setType(wechat.getType());
		response.setUrl(wechat.getUrl());
		return response;
	}
	
	public static List<WechatResponse> toResponse(List<Wechat> list)
	{
		List<WechatResponse> responseList = new ArrayList<>();
		if (list == null || list.isEmpty())
			return responseList;
		
		for (Wechat wechat : list)
		{
			responseList.add(toResponse(wechat));
		}
		return responseList;
	}
	
	public static Page<WechatResponse> toResponse(Page<Wechat> page)
	{
		if (page == null)
			return null;
		
		Page<WechatResponse> responsePage = new Page<>();
		responsePage.setCurPage(page.getCurPage());
		responsePage.setRows(page.getRows());
		responsePage.setSize(page.getSize());
		responsePage.setStartRowNo(page.getStartRowNo());
		responsePage.setTotalPage(page.getTotalPage());
		responsePage.setObjectList(toResponse(page.getObjectList()));
		return responsePage;
	}
	
}
